package com.firefly.web.controller.admin.ums;


import com.firefly.web.controller.admin.ConsoleApiRestController;
import com.firefly.service.query.ums.DepartmentQuery;
import com.firefly.dao.dao.ums.po.AdminPo;
import com.firefly.dao.dto.CommonDto;
import com.firefly.dao.dto.ums.DepartmentDto;
import com.firefly.dao.dto.ums.DepartmentStatusDto;
import com.firefly.dao.vo.ums.DepartmentVo;
import com.firefly.service.command.ums.DepartmentCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import com.firefly.dao.dto.ums.DepartmentRemoveAdminDto;

import java.util.List;
import java.util.Map;

@ConsoleApiRestController("department")
public class DepartmentController {
	private final DepartmentQuery departmentQuery;
	private final DepartmentCommand departmentService;
	@Autowired
	public DepartmentController(DepartmentQuery departmentQuery, DepartmentCommand departmentService){
		this.departmentQuery = departmentQuery;
		this.departmentService = departmentService;
	}
	
	@GetMapping("/tree")
	public List<Map> getAll() {
		return departmentQuery.tree();
	}

	@GetMapping("/select")
	public List<Map> getSelect() {
		return departmentQuery.select();
	}

	@GetMapping("/list")
	public List<DepartmentVo> getList() {
		return departmentQuery.getList();
	}
	@GetMapping("/detail")
	public DepartmentVo getDetail(@Validated(CommonDto.showDetail.class) CommonDto request) {
		return departmentQuery.detail(request.detailId);
	}

	@PostMapping("/create")
	public Object postCreate(@Validated(DepartmentDto.create.class) DepartmentDto request) {
		return departmentService.create(request);
	}
	
	@PostMapping("/update")
	public Object postUpdate(@Validated(DepartmentDto.update.class) DepartmentDto request) {
		return departmentService.update(request);
	}
	
	@PostMapping("/status")
	public Object postUpdateStatus(@Validated DepartmentStatusDto request) {
		return departmentService.changeStatus(request);
	}
	
	@PostMapping("/remove")
	public Object postRemove(@Validated(CommonDto.removeDetail.class) CommonDto request) {
		return departmentService.removeById(request.detailId);
	}
	@PostMapping("/admins")
	public List<AdminPo> postAdmins(@Validated(CommonDto.showDetail.class) CommonDto request) {
		return departmentQuery.getAdmins(request.detailId);
	}
	@PostMapping("/removeadmin")
	public Object postRemoveAdmins(@Validated DepartmentRemoveAdminDto request) {
		return departmentService.removeAdmin(request);
	}

}

